<template>
  <div class="tab-control">
    <div @click="itemClick(index)" class="tab-control-item" v-for="(item, index) in tabControlData" :key="index">
      <span :class="{active: index === currentIdx}">{{item}}</span>
    </div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        currentIdx: 0 // 记录当前处于高亮的文字
      }
    },
    props: {
      tabControlData: {
        type: Array,
        default() {
          return []
        }
      }
    },
    methods: {
      itemClick(index) {
        this.currentIdx = index
        this.$emit("tabControl", index)
      }
    }
  }
</script>

<style>
.tab-control {
  margin-top: 5px;
  margin-bottom: 5px;
  display: flex;
  text-align: center;
  height: 40px;
  line-height: 40px;
  background-color: #ffffff;
  font-size: 14px;
}
.tab-control-item {
  flex: 1;
}
.tab-control-item span {
  padding: 5px;
}
.tab-control-item span.active {
  color: red;
  border-bottom: 1px solid red;
}
</style>